package com.ruoyi.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TConsumeRecords;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TPackConsumeRecords;
import com.ruoyi.system.service.ITPackConsumeRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外包消耗记录Controller
 * 
 * @author ruoyi
 * @date 2024-07-12
 */
@RestController
@RequestMapping("/system/packConsumeRecords")
public class TPackConsumeRecordsController extends BaseController
{
    @Autowired
    private ITPackConsumeRecordsService tPackConsumeRecordsService;

    /**
     * 管理专用
     */
    @PostMapping("/allSummary")
    public AjaxResult allSummary(@RequestBody TPackConsumeRecords tPackConsumeRecords){
        return AjaxResult.success(tPackConsumeRecordsService.allSummary(tPackConsumeRecords));
    }

    /**
     * 投手专用
     */
    @PostMapping("/mySummary")
    public AjaxResult mySummary(@RequestBody TPackConsumeRecords tPackConsumeRecords){
        tPackConsumeRecords.setUid(getUserId());
        return AjaxResult.success(tPackConsumeRecordsService.mySummary(tPackConsumeRecords));
    }

    /**
     * 查询外包消耗记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:packConsumeRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPackConsumeRecords tPackConsumeRecords)
    {
        startPage();
        tPackConsumeRecords.setUid(getUserId());
        List<TPackConsumeRecords> list = tPackConsumeRecordsService.selectTPackConsumeRecordsList(tPackConsumeRecords);
        return getDataTable(list);
    }

    /**
     * 查询外包消耗记录列表(管理)
     */
    @PreAuthorize("@ss.hasPermi('system:packConsumeData:list')")
    @GetMapping("/listAdmin")
    public TableDataInfo listAdmin(TPackConsumeRecords tPackConsumeRecords)
    {
        startPage();
        List<TPackConsumeRecords> list = tPackConsumeRecordsService.selectTPackConsumeRecordsList(tPackConsumeRecords);
        return getDataTable(list);
    }
    /**
     * 设置售价
     */
    @PreAuthorize("@ss.hasPermi('system:packConsumeData:setPrice')")
    @Log(title = "外包消耗记录", businessType = BusinessType.UPDATE)
    @PostMapping("/setPrice")
    public AjaxResult setPrice(@RequestBody TPackConsumeRecords tPackConsumeRecords){
        tPackConsumeRecordsService.setPrice(tPackConsumeRecords);
        return AjaxResult.success();
    }
    /**
     * 导出外包消耗记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:packConsumeRecords:export')")
    @Log(title = "外包消耗记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPackConsumeRecords tPackConsumeRecords)
    {
        List<TPackConsumeRecords> list = tPackConsumeRecordsService.selectTPackConsumeRecordsList(tPackConsumeRecords);
        ExcelUtil<TPackConsumeRecords> util = new ExcelUtil<TPackConsumeRecords>(TPackConsumeRecords.class);
        util.exportExcel(response, list, "外包消耗记录数据");
    }

    /**
     * 获取外包消耗记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:packConsumeRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tPackConsumeRecordsService.selectTPackConsumeRecordsById(id));
    }

    /**
     * 新增外包消耗记录
     */
    @PreAuthorize("@ss.hasPermi('system:packConsumeRecords:add')")
    @Log(title = "外包消耗记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPackConsumeRecords tPackConsumeRecords)
    {
        tPackConsumeRecords.setUid(getUserId());
        return toAjax(tPackConsumeRecordsService.insertTPackConsumeRecords(tPackConsumeRecords));
    }

    /**
     * 修改外包消耗记录
     */
    @PreAuthorize("@ss.hasPermi('system:packConsumeRecords:edit')")
    @Log(title = "外包消耗记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPackConsumeRecords tPackConsumeRecords)
    {
        return toAjax(tPackConsumeRecordsService.updateTPackConsumeRecords(tPackConsumeRecords));
    }

    /**
     * 删除外包消耗记录
     */
    @PreAuthorize("@ss.hasPermi('system:packConsumeRecords:remove')")
    @Log(title = "外包消耗记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPackConsumeRecordsService.deleteTPackConsumeRecordsByIds(ids));
    }
}
